
#define ADDR_POW1 5243028

//////////////////////////////////////////////////////////////////////////////
// Standard includes
// SystemC includes
// ArchC includes

#include "ac_tlm_pow.h"
#include <math.h>

//////////////////////////////////////////////////////////////////////////////

/// Namespace to isolate mul_mem from ArchC
using user::ac_tlm_pow;

/// Constructor
ac_tlm_pow::ac_tlm_pow( sc_module_name module_name ) :
  sc_module( module_name ),
  target_export("iport")
{
    
    target_export( *this );
    /// Initialize pow_mem vector
    pow_mem = new uint8_t[24];
    for(int k=0;k<24;k++) pow_mem[k]=0;

}

/// Destructor
ac_tlm_pow::~ac_tlm_pow() {
}

/** Internal Write
  * Note: Always write 32 bits
  * @param a is the address to write
  * @param d id the data being write
  * @returns A TLM response packet with SUCCESS
*/
ac_tlm_rsp_status ac_tlm_pow::writel( const uint32_t &a , const uint32_t &d )
{
  *((uint32_t *) &pow_mem[a - ADDR_POW1]) = *((uint32_t *) &d);
 
  return SUCCESS;
}

/** Internal Read
  * Note: Always read 32 bits
  * @param a is the address to read
  * @param d id the data that will be read
  * @returns A TLM response packet with SUCCESS and a modified d
*/
ac_tlm_rsp_status ac_tlm_pow::readl( const uint32_t &a , uint32_t &d )
{

    pow_double();
 
  
  *((uint32_t *) &d) = *((uint32_t *) &pow_mem[a - ADDR_POW1]);

  return SUCCESS;

}

void ac_tlm_pow::pow_double()
{
  double d1, d2;
    d1 = *((double*)(&pow_mem[0]));
    d2 = *((double*)(&pow_mem[8]));
    *((double*)(&pow_mem[16])) = pow(d1,d2);
}

